package top.hjcwzx.wrench.design.framework.service.link.singleton.factory;

import lombok.*;
import org.springframework.stereotype.Service;
import top.hjcwzx.wrench.design.framework.link.singleton.ILogicLink;
import top.hjcwzx.wrench.design.framework.model.link.singleton.LogicSingletonReq;
import top.hjcwzx.wrench.design.framework.model.link.singleton.LogicSingletonRes;
import top.hjcwzx.wrench.design.framework.service.link.singleton.logic.TestSingletonRuleLogic01;
import top.hjcwzx.wrench.design.framework.service.link.singleton.logic.TestSingletonRuleLogic02;
import top.hjcwzx.wrench.design.framework.service.link.singleton.logic.TestSingletonRuleLogic03;


@Service
@RequiredArgsConstructor
public class DefaultTestRuleLogicFactory {

    private final TestSingletonRuleLogic01 testSingletonRuleLogic01;
    private final TestSingletonRuleLogic02 testSingletonRuleLogic02;
    private final TestSingletonRuleLogic03 testSingletonRuleLogic03;

    /**
     * 单例链组装
     * @return 返回组装的单例链
     */
    public ILogicLink<LogicSingletonReq, DynamicContext, LogicSingletonRes> openLogicLink(){
        testSingletonRuleLogic01.appendNext(testSingletonRuleLogic02).appendNext(testSingletonRuleLogic03);
        return testSingletonRuleLogic01;
    }

    /**
     * 单例链第二条组装-将影响第一条链路
     * @return 返回组装的单例链
     */
    public ILogicLink<LogicSingletonReq, DynamicContext, LogicSingletonRes> openLogicLink2(){
        testSingletonRuleLogic01.appendNext(testSingletonRuleLogic03);
        return testSingletonRuleLogic01;
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @Builder
    public static class DynamicContext {

        private String field;

    }
}
